/*
 * Copyright (c) 2019 - 2020. Boya Triz Co.,Ltd. All rights reserved. 博雅创智版权所有
 * 项目名称：cup-parent
 * 文件名称：LocalThreadParameterInterceptor.java
 * 版本：1.0
 */

package com.bytz.interceptors;


import com.bytz.common.util.RedisLockUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component("localThreadParameterInterceptor")
@Order(Ordered.HIGHEST_PRECEDENCE)
public class LocalThreadParameterInterceptor extends OncePerRequestFilter {

    @Autowired
    RedisLockUtil redisLockUtil;


    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        // 清空锁变量，防止线程外调用
        redisLockUtil.cleanThreadLocal();

        filterChain.doFilter(request, response);
    }
}
